#include <iostream>
#include <vector>
using namespace std;
int GetNum(vector<vector<int>>& Thunder, int i, int j)
{
    return Thunder[i - 1][j - 1] + Thunder[i - 1][j] + Thunder[i - 1][j + 1] + Thunder[i][j - 1] + Thunder[i][j + 1] + Thunder[i + 1][j - 1] + Thunder[i + 1][j] + Thunder[i + 1][j + 1];
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> Thunder(n + 2);
    vector<vector<int>> Count(n + 2);
    for (int i = 0; i < Count.size(); i++)
    {
        Count[i].resize(m + 2, 0);
        Thunder[i].resize(m + 2, 0);
    }
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j < m + 1; j++)
        {
            char t;
            cin >> t;
            if (t == '*')
            {
                Thunder[i][j] = 1;
            }
        }
    }
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j < m + 1; j++)
        {
            Count[i][j] = GetNum(Thunder, i, j);
            if (Thunder[i][j] == 1)
            {
                cout << '*';
            }
            else
            {
                cout << Count[i][j];
            }
        }
        cout << endl;
    }
}
